package com.yb.loadbalancer.controller;

import com.yb.core.model.XczxResult;
import com.yb.loadbalancer.client.PassportClient;
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Copyright (C), 2022-2023, 姚兵
 * Author: 32210
 * Date: 2023/5/26 13:39
 * FileName: MyController
 * Description:
 */

@RestController
@Slf4j
public class MyController {

    @Autowired
    PassportClient passportClient;

    @GetMapping("test")
    @CircuitBreaker(name = "xczxResult", fallbackMethod = "fallback")
    public XczxResult xczxResult(){
        return passportClient.loginKey();
    }

    public XczxResult fallback(Throwable throwable){
        log.info("{}",throwable);
        return XczxResult.error();
    }
}
